class FishingKing {
  final int id;
  final String userName;
  final String avatar;
  final int totalCatch; // 总钓获数量
  final double totalWeight; // 总重量(kg)
  final int biggestFish; // 最大鱼重量(g)
  final String biggestFishType; // 最大鱼类型
  final int rank; // 排名
  final int points; // 积分
  final String location; // 常钓地点
  final DateTime lastCatchTime; // 最后钓获时间
  final List<String> badges; // 徽章

  FishingKing({
    required this.id,
    required this.userName,
    required this.avatar,
    required this.totalCatch,
    required this.totalWeight,
    required this.biggestFish,
    required this.biggestFishType,
    required this.rank,
    required this.points,
    required this.location,
    required this.lastCatchTime,
    required this.badges,
  });

  factory FishingKing.fromJson(Map<String, dynamic> json) {
    return FishingKing(
      id: json['id'] ?? 0,
      userName: json['userName'] ?? '',
      avatar: json['avatar'] ?? '',
      totalCatch: json['totalCatch'] ?? 0,
      totalWeight: double.tryParse(json['totalWeight'].toString()) ?? 0.0,
      biggestFish: json['biggestFish'] ?? 0,
      biggestFishType: json['biggestFishType'] ?? '',
      rank: json['rank'] ?? 0,
      points: json['points'] ?? 0,
      location: json['location'] ?? '',
      lastCatchTime: DateTime.tryParse(json['lastCatchTime'] ?? '') ?? DateTime.now(),
      badges: List<String>.from(json['badges'] ?? []),
    );
  }

  Map<String, dynamic> toJson() {
    return {
      'id': id,
      'userName': userName,
      'avatar': avatar,
      'totalCatch': totalCatch,
      'totalWeight': totalWeight,
      'biggestFish': biggestFish,
      'biggestFishType': biggestFishType,
      'rank': rank,
      'points': points,
      'location': location,
      'lastCatchTime': lastCatchTime.toIso8601String(),
      'badges': badges,
    };
  }
}